package cn.getech.data.development.constant;


import lombok.Getter;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zenith
 * @Description 所有连接类型的枚举
 */
@Getter
public enum ConnectTypeEnum {

    MySQL(1, ConTypeType.JDBC, "MySQL", "com.mysql.jdbc.Driver", "jdbc:mysql://<host>:<port>/<db_name>", true, true, true, "jdbc:mysql://<host>:<port>"),
    Oracle(2, ConTypeType.JDBC, "Oracle", "oracle.jdbc.OracleDriver", "jdbc:oracle:thin:@//<host>:<port>/<db_name>", true, true, true, "jdbc:oracle:thin:@//<host>:<port>"),
    //SQL_Server(3,ConTypeType.JDBC,"sqlserver", "com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://<host>:<port>;databaseName=<db_name>",true,true,true),
    SQL_Server(3, ConTypeType.JDBC, "SQL Server", "net.sourceforge.jtds.jdbc.Driver",
            "jdbc:jtds:sqlserver://<host>:<port>;DatabaseName=<db_name>", true, true, true, "jdbc:jtds:sqlserver://<host>:<port>"),
    /**
     * sqlserver:
     *   datasource:
     *     url: jdbc:jtds:sqlserver://{ip}:{port};DatabaseName={}
     *     driverClassName: net.sourceforge.jtds.jdbc.Driver
     */
    PostgreSQL(4, ConTypeType.JDBC, "PostgreSQL", "org.postgresql.Driver", "jdbc:postgresql://<host>:<port>/<db_name>", true, true, true, "jdbc:postgresql://<host>:<port>"),
    SAPHANA(10, ConTypeType.JDBC, "SAP HANA", "com.sap.db.jdbc.Driver", "jdbc:sap://<host>:<port>?reconnect=true", true, true, true, "jdbc:sap://<host>:<port>?reconnect=true"),
    FTP(5, ConTypeType.FTP, "FTP", "", "", true, false, true, ""),
    Kafka(6, ConTypeType.KAFKA, "Kafka", "", "", false, false, true, ""),
    JieKou(7, ConTypeType.JieKou, "接口", "", "", true, false, true, ""),
    Sap(8, ConTypeType.Sap, "SAP", "", "", true, false, true, ""),
    WebService(9, ConTypeType.WebService, "WebService", "", "", true, false, true, ""),
    Hive(11, ConTypeType.JDBC, "Hive", "org.apache.hive.jdbc.HiveDriver", "jdbc:hive2://<host>:<port>/<db_name>", false, false, true, "jdbc:hive2://<host>:<port>"),
    ElasticSearch(12, ConTypeType.ES, "ElasticSearch", "", "", true, false, true, ""),
    HBase(13, ConTypeType.HBase, "Hbase", "", "", false, false, true, ""),
    // kudu  //auth=noSasl不使用Kerberos身份验证的群集执行此操作
   // Kudu(14, ConTypeType, "Kudu", "org.apache.hive.jdbc.HiveDriver", "jdbc:hive2://<host>:<port>/<db_name>;auth=noSasl;AuthMech=3", true, true, true, "jdbc:hive2://<host>:<port>;auth=noSasl;AuthMech=3"),

    // kudu 客户端直接连接方式
    Kudu(14, ConTypeType.Kudu, "Kudu", "", "", false, true, true, ""),
    //clickhouse
    ClickHouse(15, ConTypeType.JDBC, "ClickHouse", "ru.yandex.clickhouse.ClickHouseDriver", "jdbc:clickhouse://<host>:<port>/<db_name>", false, true, true, "jdbc:clickhouse://<host>:<port>"),

    OracleNTS(16, ConTypeType.OracleNTS, "OracleNTS", "oracle.jdbc.OracleDriver", "jdbc:oracle:thin:@//<host>:<port>/<db_name>", true, true, true, "jdbc:oracle:thin:@//<host>:<port>"),
    MongoDB(17, ConTypeType.MongoDB, "MongoDB", "", "mongodb://<host>:<port>/<db_name>", false, false, true, "mongo://<host>:<port>"),
    SFTP(18, ConTypeType.SFTP, "SFTP", "", "", true, false, true, ""),
    ;

    ConnectTypeEnum(int code, ConTypeType type, String name, String driverClass, String url, Boolean isInput, Boolean isOutput, Boolean enable, String url2) {
        this.code = code;
        this.type = type;
        this.name = name;
        this.driverClass = driverClass;
        this.url = url;
        this.isInput = isInput;
        this.isOutput = isOutput;
        this.enable = enable;
        this.url2 = url2;
    }

    public static ConnectTypeEnum ObjOf(Integer code) {
        if (code == null) {
            return null;
        } else {
            for (ConnectTypeEnum s : ConnectTypeEnum.values()) {
                if (s.getCode().equals(code)) {
                    return s;
                }
            }
            return null;
        }
    }

    public static ConnectTypeEnum getCodeByName(String name) {
        if (StringUtils.isBlank(name)) {
            return null;
        } else {
            for (ConnectTypeEnum s : ConnectTypeEnum.values()) {
                if (StringUtils.equals(s.getName(), name)) {
                    return s;
                }
            }
            return null;
        }
    }

    public static List<Integer> getCodeByConType() {
        return Arrays.stream(ConnectTypeEnum.values()).filter(connectTypeEnum -> {
            return connectTypeEnum.getType().getCode() == 0;
        }).map(ConnectTypeEnum::getCode).collect(Collectors.toList());
    }


    private Integer code;
    private ConTypeType type;
    private String name;
    private String driverClass;
    private String url;
    private Boolean enable;
    private Boolean isInput;
    private Boolean isOutput;
    private String url2;
}
